package com.yupi.yupao.config;
 
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * 自定义 Swagger 接口文档的配置
 *
 * @author
 * @from
 */
@Configuration
//@EnableSwagger2WebMvc
@EnableSwagger2
@Profile({"dev", "test"})
@Slf4j
public class SwaggerConfig {
    @Bean
    public Docket docket1() {
        log.info("准备生成接口文档");

        ApiInfo apiInfo = new ApiInfoBuilder()
                .title("伙伴匹配接口文档")
                .version("2.0")
                .description("伙伴匹配接口文档")
                .termsOfServiceUrl("https://github.com/yupi")
                .contact(new Contact("yupi","https://github.com/liyupi","xxx@qq.com"))
                .build();
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .groupName("伙伴匹配")
                .apiInfo(apiInfo)
                .select()
//                .apis(RequestHandlerSelectors.basePackage("com/yupi/yupao/controller"))
                .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }

//    @Bean
//    public Docket defaultApi2() {
//        return new Docket(DocumentationType.SWAGGER_2)
//                .apiInfo(apiInfo())
//                .groupName("伙伴匹配")
//                .select()
//                // 这里一定要标注你控制器的位置
//                .apis(RequestHandlerSelectors.basePackage("com/yupi/yupao/controller"))
////               .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
//                .paths(PathSelectors.any())
//                .build();
//    }
//
//    /**
//     * api 信息
//     * @return
//     */
//    private ApiInfo apiInfo() {
//        return new ApiInfoBuilder()
//                .title("伙伴匹配")
//                .description("伙伴匹配")
//                .termsOfServiceUrl("https://github.com/yupi")
//                .contact(new Contact("yupi","https://github.com/liyupi","xxx@qq.com"))
//                .version("1.0")
//                .build();
//    }
}

